package com.elite.groovy.davco.init;

import com.elite.groovy.kh.HttpClientUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @projectName: Degao_Clink
 * @package: com.elite.groovy.davco.clink
 * @className: SignUtil
 * @description: TODO
 * @author: LiJT
 * @date: 2023-10-27 11:13
 * @version: 1.0
 */
public class initClinkReport {
    private static final Log log = LogFactory.getLog(initClinkReport.class);

    public static void main(String[] args) throws Exception {
        // 创建日期格式对象并设置要输出的格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        String StartTime = "";

        // 设置起始日期为2022年10月1日
        Calendar startDate = Calendar.getInstance();
        startDate.set(Calendar.YEAR, 2022);
        startDate.set(Calendar.MONTH, 9);
        startDate.set(Calendar.DAY_OF_MONTH, 30);

        // 获取当前日期
        Calendar currentDate = Calendar.getInstance();

        int loopLimit = 0;
        while ((startDate.before(currentDate) || startDate.equals(currentDate)) && loopLimit < 800) {
            StartTime = sdf.format(startDate.getTime());
            System.out.println("♻同步日期:" + StartTime);
            log.debug("doCallBack Data StartTime:" + StartTime);

            // 在此处添加其他需要执行的操作或业务逻辑
            String syncRes = HttpClientUtil.get("https://ccctest.davco.cn/groovy/call/apiClinkReportData?StartTime=" + StartTime);
            log.debug("doCallBack Data syncRes:" + syncRes);

            startDate.add(Calendar.DATE, 1);

            loopLimit++;

        }

    }

    /*
     * 将时间字符串转换为时间戳
     */
    public static String dateToStamp(String s) {
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = simpleDateFormat.parse(s);
        } catch (Exception e) {
            log.error("dateToStamp Exception:" + e.getMessage());
        }

        long ts = date.getTime();
        res = String.valueOf(ts).substring(0, String.valueOf(ts).length() - 3);
        ;
        return res;
    }
}
